package com.example.xlmkotlinwanandroid.data.remote.remotedata

import com.example.xlmkotlinwanandroid.data.Resource
import com.example.xlmkotlinwanandroid.data.remote.RetrofitGenerator
import com.example.xlmkotlinwanandroid.data.remote.service.RemoteService
import com.example.xlmkotlinwanandroid.model.bean.BannerBean
import com.example.xlmkotlinwanandroid.network.BaseResponse
import retrofit2.Response
import java.lang.Exception

/**
 *  author : cailei
 *  date : 2022/3/18
 *  description :
 */

const val NET_WORK_ERROR = -2


class RemoteData : BaseData(), RemoteDataSource {

    private val service = RetrofitGenerator.createService(RemoteService::class.java)

    override suspend fun getBanners(): Resource<ArrayList<BannerBean>> {
//        service.getBannerList()
        return when (val response = processCall(service::getBannerList)) {
            is List<*> -> {
                Resource.Success(response as ArrayList<BannerBean>)
            }
            else -> {
                Resource.DataError(response as Int)
            }
        }
    }


}